package cn.tedu.fruitshop.config;

import lombok.extern.slf4j.Slf4j;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;
import org.springframework.data.redis.connection.RedisConnectionFactory;
import org.springframework.data.redis.core.RedisTemplate;
import org.springframework.data.redis.serializer.RedisSerializer;

import java.io.Serializable;

/**
 * @ClassName:RedisConfiguration
 * @Description:Redis 的配置类
 * @author: www
 * @date:2022-10-24 16:38
 * @Version 1.0
 */
@Slf4j
@Configuration
public class RedisConfiguration {
    public RedisConfiguration() {
        log.debug("创建配置类对象：RedisConfiguration");
    }
    @Bean
    public RedisTemplate<String, Serializable> redisTemplate(RedisConnectionFactory redisConnectionFactory){
        RedisTemplate<String, Serializable> redisTemplate = new RedisTemplate<>();
        //设置连接工厂。ConnectionFactory
        redisTemplate.setConnectionFactory(redisConnectionFactory);
        //需要设置key的序列化-->字符串
        redisTemplate.setKeySerializer(RedisSerializer.string());
        //设置value的序列化-->JSON容易传输
        redisTemplate.setValueSerializer(RedisSerializer.json());
        return redisTemplate;
    }

}
